<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="button" value="click" id="btn">
    <script>
        function Fruit(name,color){
            var t = 2;
            this.name = name;
            this.color = color;
            this.originPlace = function(){
                console.log('海南');
            };
            this.show = function(){
                console.log(this.name);
                console.log(this.color);
                return t;
            };
            this.setT = function(v){
                var reg = /^[012]$/;
                if(reg.test(v)){
                    t = v;
                }else{
                    try {
                        throw new Error("Can't set t beyond 0~2");
                    } catch(e) {
                        console.log(e);
                    }
                }
            };
        }
        var Banana = new Fruit('Banana','Orange');

        document.getElementById('btn').onclick = function(){
            // (function(that){
            //     console.log(that);
            //     that.value = 'doubleClick';
            // })(this);
            +function(){
                console.log(this);
                this.value = 'dbclick';
            }.call(this);
        };


    	function person(){
            this.say();
            console.log(this.name);
        }
        var Obj = {
            name:'Banana',
            say: function(){
                console.log('say hi');
            }
        }
        // person.call(Obj);
        var John = {
            name:'John',
            age:'23',
            say:function(){
                console.log(this.name+ '今年' + this.age +'岁');
            },
            greeting:function(){
                var that = this;  //将this指向的引用赋值给that
                function greet(){
                    'use strict';
                    console.log(that.name);
                }
                greet();
            },
            greeting1:function(){
                function greet(){
                    'use strict';
                    console.log(this.name);
                }
                greet.call(this);
            },
            birthday:function(){
                this.age++;
            },
        }

    </script>
</body>
</html>